package entity

import (
	"kop/modules/building/configuration"
	"time"
)

type Dispatch struct {
	RoleID     int32 `gorm:"type:int;primary_key"`
	DispatchID int32 `gorm:"type:int;primary_key"`
	ShipID     int32
	Peerage    int32 // 任务开始时爵位
	CreatedAt  time.Time
	UpdatedAt  time.Time
}

// 距离完成剩余时间
func (e Dispatch) GetTime() int32 {

	var conf = configuration.GetDispatch(e.DispatchID)

	if e.ShipID > 0 {
		var sec = e.UpdatedAt.Add(time.Minute * time.Duration(conf.Time)).Sub(time.Now()).Seconds()
		if sec > 0 {
			return int32(sec)
		}
	}

	return 0
}
